package com.enbatis.mybatisplugs.service.impl;

import com.enbatis.mybatisplugs.base.BaseServiceImpl;

import com.enbatis.mybatisplugs.base.IRedisService;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.entity.NewsData;
import com.enbatis.mybatisplugs.mapper.NewsDataMapper;
import com.enbatis.mybatisplugs.plugin.Pages;
import com.enbatis.mybatisplugs.service.NewsDataService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 描述：
* @author wangweidong
* @date 2019-11-12 14:30:50
*/

@Service
public class NewsDataServiceImpl extends BaseServiceImpl<NewsDataMapper,NewsData > implements NewsDataService {

    @Autowired
    private IRedisService redisService;


    @Override
    public Pages<NewsData> pageNews(Page<NewsData> page, Wrapper<NewsData> wrapper) {
        Page returnPage= PageHelper.startPage(page.getPageNum(),page.getPageSize(),page.getOrderBy());
        List<NewsData> list;
        if (null==redisService.getList("newsDataRedis")){
            list= baseMapper.page(wrapper);
            redisService.setList("newsDataRedis",list);
        }else{
            list= redisService.getList("newsDataRedis");
        }


        Pages<NewsData> pages=new Pages<>(returnPage);
        return pages;
    }
}
